/*
package wu.controller;

import org.apache.ibatis.session.SqlSession;
import wu.mapper.StudentMapper;
import wu.pojo.NiuStudent;
import wu.util.MyBatisUtils;

import java.util.*;

public class getHtmlJsDataString {
    private static final SqlSession sqlSession = MyBatisUtils.getSession();
    private static final StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
    private static List<NiuStudent> list = new ArrayList<>();
    private static List<NiuStudent> list_oid = new ArrayList<>();
    private static String dataString = "";

    public String getDataString(int num) {
        list = setListNiuStudent(num, list);
        data=data+"\n\n\n\n\n\n");
        list_oid = setListNiuStudent(num - 1, list_oid);
        List<NiuStudent> ll = null;
        int[] listsize = new int[7];
        listsize[0] = list.size();
        listsize[1] = list_oid.size();
        for (int i = 2; i < listsize.length; i++) {
            ll = new ArrayList<>();
            listsize[i] = setListNiuStudent(num - i, ll).size();
        }

        dataString = "\n\n\n\n\n\n" + "<script type=\"text/javascript\">\nconst num= " + num + ";";
        dataString=dataString+left2(num, list);
        dataString=dataString+left3(num);
        dataString=dataString+center1(num, list);
        dataString=dataString+center2(num);
        dataString=dataString+right1(num);
        dataString=dataString+right2(num, listsize);
        dataString=dataString+right3(num);
        dataString=dataString+"</script>";
        sqlSession.close();
        return dataString;
    }

    private static String left2(int num, List<NiuStudent> list) {
        String data="";
        int len = 7;
        double[] values = new double[len * 2];
        for (NiuStudent niuStudent1 : list) {
            if (niuStudent1.getA_score() != -1) {
                values[0] += niuStudent1.getA_score();
            }
            if (niuStudent1.getB_score() != -1) {
                values[1] += niuStudent1.getB_score();
            }
            if (niuStudent1.getC_score() != -1) {
                values[2] += niuStudent1.getC_score();
            }
            if (niuStudent1.getD_score() != -1) {
                values[3] += niuStudent1.getD_score();
            }
            if (niuStudent1.getE_score() != -1) {
                values[4] += niuStudent1.getE_score();
            }
            if (niuStudent1.getF_score() != -1) {
                values[5] += niuStudent1.getF_score();
            }
            if (niuStudent1.getG_score() != -1) {
                values[6] += niuStudent1.getG_score();
            }
        }
        data=data+"const left2= [";
        for (int ii = 0; ii < len; ii++) {
            data=data+"{value:" + String.format("%.2f", values[ii]) + ",name: '" + (char) ('A' + ii) + "'}";

            if (ii != len - 1) {
                data=data+",");
            }
        }
        data=data+"];");
        return data;
    }

    private static String left3(int num) {
        String data="";
        int len = 7;
        int[] arr1 = new int[len], arr2 = new int[len], arr3 = new int[len];
        for (NiuStudent niuStudent1 : list_oid) {
            if (niuStudent1.getB_score() != -1) {
                arr1[1]++;
            }
            if (niuStudent1.getC_score() != -1) {
                arr1[2]++;
            }
            if (niuStudent1.getD_score() != -1) {
                arr1[3]++;
            }
            if (niuStudent1.getE_score() != -1) {
                arr1[4]++;
            }
            if (niuStudent1.getF_score() != -1) {
                arr1[5]++;
            }
            if (niuStudent1.getG_score() != -1) {
                arr1[6]++;
            }
            if (niuStudent1.getA_score() != -1) {
                arr1[0]++;
            }
        }
        for (NiuStudent niuStudent : list) {
            if (niuStudent.getB_score() != -1) {
                arr2[1]++;
            }
            if (niuStudent.getC_score() != -1) {
                arr2[2]++;
            }
            if (niuStudent.getD_score() != -1) {
                arr2[3]++;
            }
            if (niuStudent.getE_score() != -1) {
                arr2[4]++;
            }
            if (niuStudent.getF_score() != -1) {
                arr2[5]++;
            }
            if (niuStudent.getG_score() != -1) {
                arr2[6]++;
            }
            if (niuStudent.getA_score() != -1) {
                arr2[0]++;
            }
        }
        for (int i = 0; i < len; i++) {
            arr3[i] = arr2[i] - arr1[i];
        }
        data=data+"const left3_data1= [");
        for (int ii = 0; ii < len; ii++) {
            data=data+"'" + arr1[ii] + "'");
            if (ii != len - 1) {
                data=data+",");
            }
        }
        data=data+"];");
        data=data+"const left3_data2= [");
        for (int ii = 0; ii < len; ii++) {
            data=data+"'" + arr2[ii] + "'");
            if (ii != len - 1) {
                data=data+",");
            }
        }
        data=data+"];");
        data=data+"const left3_data3= [");
        for (int ii = 0; ii < len; ii++) {
            data=data+"'" + arr3[ii] + "'");
            if (ii != len - 1) {
                data=data+",");
            }
        }
        data=data+"];");
        return data;
    }

    private static String center1(int num, List<NiuStudent> list) {
        String data="";
        int len = 7;
        double[] values = new double[len * 2];
        for (NiuStudent niuStudent1 : list) {
            if (niuStudent1.getA_score() != -1) {
                values[0] += niuStudent1.getA_score();
            }
            if (niuStudent1.getB_score() != -1) {
                values[1] += niuStudent1.getB_score();
            }
            if (niuStudent1.getC_score() != -1) {
                values[2] += niuStudent1.getC_score();
            }
            if (niuStudent1.getD_score() != -1) {
                values[3] += niuStudent1.getD_score();
            }
            if (niuStudent1.getE_score() != -1) {
                values[4] += niuStudent1.getE_score();
            }
            if (niuStudent1.getF_score() != -1) {
                values[5] += niuStudent1.getF_score();
            }
            if (niuStudent1.getG_score() != -1) {
                values[6] += niuStudent1.getG_score();
            }
        }
        data=data+"const center1= [");
        String[] names = {"A", "B", "C", "D", "E", "F", "G", "", "", "", "", "", "", ""};
        String[] colors = {"#f845f1", "#ad46f3", "#5045f6", "#4777f5", "#44aff0", "#45dbf7", "#f6d54a", "transparent", "transparent", "transparent", "transparent", "transparent", "transparent", "transparent"};
        for (int i = 0; i < len; i++) {
            data=data+"{value: ");
            System.out.printf("%.2f", values[i]);
            data=data+",name:\'");
            data=data+names[i]);
            data=data+"\',itemStyle: {normal: {color:\'");
            data=data+colors[i]);
            data=data+"\'}}}");
            data=data+",");
        }
        for (int i = len; i < len * 2; i++) {
            data=data+"{value: ");
            data=data+values[i]);
            data=data+",name:\'");
            data=data+names[i]);
            data=data+"\',itemStyle: {normal: {color:\'");
            data=data+colors[i]);
            data=data+"\'}},label: {show: false},labelLine: {show: false}}");
            if (len * 2 - 1 != i)
                data=data+",");
        }
        data=data+"];");
        return data;

    }

    public static String center2(int num) {
        String data="";
        data=data+"const center2= [");
        int len = list.size();
        for (int ii = 0; ii < len; ii++) {
            data=data+"[\'");
            data=data+ii + 1);
            data=data+"\',\'");
            data=data+list.get(ii).getClassInfo());
            data=data+"\',\'");
            data=data+list.get(ii).getName());
            data=data+"\',\'");
            data=data+list.get(ii).getNiu_Contestants());
            data=data+"\',\'");
            data=data+list.get(ii).getNiu_id());
            data=data+"\',\'");
            data=data+list.get(ii).getNiu_Ranking());
            data=data+"\',\'");
            data=data+list.get(ii).getNiu_School());
            data=data+"\',\'");
            data=data+list.get(ii).getNiu_AC());
            data=data+"\',\'");
            data=data+list.get(ii).getNiu_total_score());
            data=data+"\',\'");
            data=data+list.get(ii).getNiu_time());
            data=data+"\']");
            if (ii != len - 1) {
                data=data+",");
            }
        }
        System.out.println();
        data=data+"];");

        return data;
    }

    private static String right1(int num) {
        String data="";
        int len = 7;
        int[] arr1 = new int[len], arr2 = new int[len], arr3 = new int[len];
        for (NiuStudent niuStudent1 : list) {
            if (niuStudent1.getB_score() != -1) {
                arr1[1]++;
            }
            if (niuStudent1.getC_score() != -1) {
                arr1[2]++;
            }
            if (niuStudent1.getD_score() != -1) {
                arr1[3]++;
            }
            if (niuStudent1.getE_score() != -1) {
                arr1[4]++;
            }
            if (niuStudent1.getF_score() != -1) {
                arr1[5]++;
            }
            if (niuStudent1.getG_score() != -1) {
                arr1[6]++;
            }
            if (niuStudent1.getA_score() != -1) {
                arr1[0]++;
            }
        }
        data=data+"const right1= [");
        String[] names = {"A", "B", "C", "D", "E", "F", "G"};
        for (int i = 0; i < len; i++) {
            data=data+"{value: " + arr1[i]);
            data=data+",name: '" + names[i] + "'}");
            if (i != len - 1) {
                data=data+",");
            }
        }
        data=data+"];");
        return data;
    }

    private static String right2(int num, int[] listsize) {
        String data="";
        data=data+"const right2_data1= [");
        for (int ii = 0; ii < 7; ii++) {
            data=data+"\'" + (num - 6 + ii) + "周\'");
            if (ii != 6) {
                data=data+",");
            }
        }
        data=data+"];");
        data=data+"const right2_data2= [");
//        for (int i = 0; i < 7; i++) {
        for (int i = 6; i >= 0; i--) {
            data=data+listsize[i]);
            if (i != 0) {
                data=data+",");
            }
        }
        data=data+"];");
        return data;
    }

    private static String right3(int num) {
        String data="";
        data=data+"const right3= [");
        int len = list_oid.size();
        for (int ii = 0; ii < len; ii++) {
            data=data+"[\'");
            data=data+ii + 1);
            data=data+"\',\'");
            for (int i1 = 0; i1 < list.size(); i1++) {
                if (list.get(i1).getNiu_id() == list_oid.get(ii).getNiu_id()) {
                    if (i1 == ii) {
                        data=data+"⊜");
                    } else if (i1 < ii) {
                        data=data+"⇪");
                    } else {
                        data=data+"⇩");
                    }
                    break;
                }
                if (i1 == list.size() - 1) {
                    data=data+"⌀");
                }
            }
            data=data+"\',\'");
            data=data+list_oid.get(ii).getClassInfo());
            data=data+"\',\'");
            data=data+list_oid.get(ii).getName());
            data=data+"\',\'");
            data=data+list_oid.get(ii).getNiu_total_score());
            data=data+"\',\'");
            data=data+list_oid.get(ii).getNiu_time());
            data=data+"\']");
            if (ii != len - 1) {
                data=data+",");
            }
        }
        System.out.println();
        data=data+"];");

        return data;
    }

    private static List<NiuStudent> setListNiuStudent(int num, List<NiuStudent> list2) {
        List<Integer> niuIds = studentMapper.getNiuIds();
        for (Integer niuId : niuIds) {
            NiuStudent niuStudent = studentMapper.getStudentByIdAndTableName("user_table_" + num, niuId);
            // 处理查询到的学生和相关 User_niu 信息
            if (niuStudent != null) {
                list2.add(niuStudent);
            }
        }
        // 创建一个Comparator接口实现，用于比较两个NiuStudent对象的niu_total_score属性
        Comparator<NiuStudent> comparator = new Comparator<NiuStudent>() {
            @Override
            public int compare(NiuStudent s1, NiuStudent s2) {
                if (s1.getNiu_total_score() == null) {
                    return 1;
                }
                if (s2.getNiu_total_score() == null) {
                    return -1;
                }
                // 将字符串转换为double类型后进行比较
                double score1 = Double.parseDouble(s1.getNiu_total_score());
                double score2 = Double.parseDouble(s2.getNiu_total_score());
                if (score2 > score1) {
                    return 1;
                } else if (score2 < score1) {
                    return -1;
                } else {
                    return s1.getNiu_time().compareTo(s2.getNiu_time());
                }
            }
        };
        // 使用Collections.sort方法对列表进行排序
        Collections.sort(list2, comparator);
        return list2;
    }
}
*/
package wu.service;

import org.apache.ibatis.session.SqlSession;
import wu.mapper.StudentMapper;
import wu.pojo.NiuStudent;
import wu.util.MyBatisUtils;

import java.util.*;

public class getHtmlJsDataString {
    private static final SqlSession sqlSession = MyBatisUtils.getSession();
    private static final StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
    private static List<NiuStudent> list = new ArrayList<>();
    private static List<NiuStudent> list_oid = new ArrayList<>();
    private static String dataString = "";

//    public static void main(String[] args) {
//        getHtmlJsDataString getHtmlJsDataString = new getHtmlJsDataString();
//        System.out.println(getHtmlJsDataString.getDataString(71));
//    }

    public String getDataString(int num) {
        list = setListNiuStudent(num, list);
        list_oid = setListNiuStudent(num - 1, list_oid);
        List<NiuStudent> ll = null;
        int[] listsize = new int[7];
        listsize[0] = list.size();
        listsize[1] = list_oid.size();
        for (int i = 2; i < listsize.length; i++) {
            ll = new ArrayList<>();
            listsize[i] = setListNiuStudent(num - i, ll).size();
        }

        dataString = "\n<!--数据*/*/*/*￥#&1-->\n<script type=\"text/javascript\">\nconst num= " + num + ";";
        dataString += left2(num, list);
        dataString += left3(num);
        dataString += center1(num, list);
        dataString += center2(num);
        dataString += right1(num);
        dataString += right2(num, listsize);
        dataString += right3(num);
        dataString += "</script>";
        dataString += "\n<!--数据*/*/*/*￥#&2-->\n";
        sqlSession.close();
        return dataString;
    }

    private static String left2(int num, List<NiuStudent> list) {
        StringBuilder data = new StringBuilder();
        int len = 7;
        double[] values = new double[len * 2];
        for (NiuStudent niuStudent1 : list) {
            if (niuStudent1.getA_score() != -1) {
                values[0] += niuStudent1.getA_score();
            }
            if (niuStudent1.getB_score() != -1) {
                values[1] += niuStudent1.getB_score();
            }
            if (niuStudent1.getC_score() != -1) {
                values[2] += niuStudent1.getC_score();
            }
            if (niuStudent1.getD_score() != -1) {
                values[3] += niuStudent1.getD_score();
            }
            if (niuStudent1.getE_score() != -1) {
                values[4] += niuStudent1.getE_score();
            }
            if (niuStudent1.getF_score() != -1) {
                values[5] += niuStudent1.getF_score();
            }
            if (niuStudent1.getG_score() != -1) {
                values[6] += niuStudent1.getG_score();
            }
        }
        data.append("const left2= [");
        for (int ii = 0; ii < len; ii++) {
            data.append("{value:").append(String.format("%.2f", values[ii])).append(",name: '").append((char) ('A' + ii)).append("'}");

            if (ii != len - 1) {
                data.append(",");
            }
        }
        data.append("];");
        return data.toString();
    }

    private static String left3(int num) {
        StringBuilder data = new StringBuilder();
        int len = 7;
        int[] arr1 = new int[len], arr2 = new int[len], arr3 = new int[len];
        for (NiuStudent niuStudent1 : list_oid) {
            if (niuStudent1.getB_score() != -1) {
                arr1[1]++;
            }
            if (niuStudent1.getC_score() != -1) {
                arr1[2]++;
            }
            if (niuStudent1.getD_score() != -1) {
                arr1[3]++;
            }
            if (niuStudent1.getE_score() != -1) {
                arr1[4]++;
            }
            if (niuStudent1.getF_score() != -1) {
                arr1[5]++;
            }
            if (niuStudent1.getG_score() != -1) {
                arr1[6]++;
            }
            if (niuStudent1.getA_score() != -1) {
                arr1[0]++;
            }
        }
        for (NiuStudent niuStudent : list) {
            if (niuStudent.getB_score() != -1) {
                arr2[1]++;
            }
            if (niuStudent.getC_score() != -1) {
                arr2[2]++;
            }
            if (niuStudent.getD_score() != -1) {
                arr2[3]++;
            }
            if (niuStudent.getE_score() != -1) {
                arr2[4]++;
            }
            if (niuStudent.getF_score() != -1) {
                arr2[5]++;
            }
            if (niuStudent.getG_score() != -1) {
                arr2[6]++;
            }
            if (niuStudent.getA_score() != -1) {
                arr2[0]++;
            }
        }
        for (int i = 0; i < len; i++) {
            arr3[i] = arr2[i] - arr1[i];
        }
        data.append("const left3_data1= [");
        for (int ii = 0; ii < len; ii++) {
            data.append("'").append(arr1[ii]).append("'");
            if (ii != len - 1) {
                data.append(",");
            }
        }
        data.append("];");
        data.append("const left3_data2= [");
        for (int ii = 0; ii < len; ii++) {
            data.append("'").append(arr2[ii]).append("'");
            if (ii != len - 1) {
                data.append(",");
            }
        }
        data.append("];");
        data.append("const left3_data3= [");
        for (int ii = 0; ii < len; ii++) {
            data.append("'").append(arr3[ii]).append("'");
            if (ii != len - 1) {
                data.append(",");
            }
        }
        data.append("];");
        return data.toString();
    }

    private static String center1(int num, List<NiuStudent> list) {
        StringBuilder data = new StringBuilder();
        int len = 7;
        double[] values = new double[len * 2];
        for (NiuStudent niuStudent1 : list) {
            if (niuStudent1.getA_score() != -1) {
                values[0] += niuStudent1.getA_score();
            }
            if (niuStudent1.getB_score() != -1) {
                values[1] += niuStudent1.getB_score();
            }
            if (niuStudent1.getC_score() != -1) {
                values[2] += niuStudent1.getC_score();
            }
            if (niuStudent1.getD_score() != -1) {
                values[3] += niuStudent1.getD_score();
            }
            if (niuStudent1.getE_score() != -1) {
                values[4] += niuStudent1.getE_score();
            }
            if (niuStudent1.getF_score() != -1) {
                values[5] += niuStudent1.getF_score();
            }
            if (niuStudent1.getG_score() != -1) {
                values[6] += niuStudent1.getG_score();
            }
        }
        data.append("const center1= [");
        String[] names = {"A", "B", "C", "D", "E", "F", "G", "", "", "", "", "", "", ""};
        String[] colors = {"#f845f1", "#ad46f3", "#5045f6", "#4777f5", "#44aff0", "#45dbf7", "#f6d54a", "transparent", "transparent", "transparent", "transparent", "transparent", "transparent", "transparent"};
        for (int i = 0; i < len; i++) {
            data.append("{value: ");
            data.append(String.format("%.2f", values[i]));
            data.append(",name:'");
            data.append(names[i]);
            data.append("',itemStyle: {normal: {color:'");
            data.append(colors[i]);
            data.append("'}}}");
            data.append(",");
        }
        for (int i = len; i < len * 2; i++) {
            data.append("{value: ");
            data.append(values[i]);
            data.append(",name:'");
            data.append(names[i]);
            data.append("',itemStyle: {normal: {color:'");
            data.append(colors[i]);
            data.append("'}},label: {show: false},labelLine: {show: false}}");
            if (len * 2 - 1 != i)
                data.append(",");
        }
        data.append("];");
        return data.toString();
    }

    public static String center2(int num) {
        StringBuilder data = new StringBuilder();
        data.append("const center2= [");
        int len = list.size();
        for (int ii = 0; ii < len; ii++) {
            data.append("[").append(ii + 1).append(",'");
            data.append(list.get(ii).getClassInfo()).append("','");
            data.append(list.get(ii).getName()).append("','");
            data.append(list.get(ii).getNiu_Contestants()).append("','");
            data.append(list.get(ii).getNiu_id()).append("','");
            data.append(list.get(ii).getNiu_Ranking()).append("','");
            data.append(list.get(ii).getNiu_School()).append("','");
            data.append(list.get(ii).getNiu_AC()).append("','");
            data.append(list.get(ii).getNiu_total_score()).append("','");
            data.append(list.get(ii).getNiu_time()).append("']");
            if (ii != len - 1) {
                data.append(",");
            }
        }
        System.out.println();
        data.append("];");

        return data.toString();
    }

    private static String right1(int num) {
        StringBuilder data = new StringBuilder();
        int len = 7;
        int[] arr1 = new int[len], arr2 = new int[len], arr3 = new int[len];
        for (NiuStudent niuStudent1 : list) {
            if (niuStudent1.getB_score() != -1) {
                arr1[1]++;
            }
            if (niuStudent1.getC_score() != -1) {
                arr1[2]++;
            }
            if (niuStudent1.getD_score() != -1) {
                arr1[3]++;
            }
            if (niuStudent1.getE_score() != -1) {
                arr1[4]++;
            }
            if (niuStudent1.getF_score() != -1) {
                arr1[5]++;
            }
            if (niuStudent1.getG_score() != -1) {
                arr1[6]++;
            }
            if (niuStudent1.getA_score() != -1) {
                arr1[0]++;
            }
        }
        data.append("const right1= [");
        String[] names = {"A", "B", "C", "D", "E", "F", "G"};
        for (int i = 0; i < len; i++) {
            data.append("{value: ").append(arr1[i]).append(",name: '").append(names[i]).append("'}");
            if (i != len - 1) {
                data.append(",");
            }
        }
        data.append("];");
        return data.toString();
    }

    private static String right2(int num, int[] listsize) {
        StringBuilder data = new StringBuilder();
        data.append("const right2_data1= [");
        for (int ii = 0; ii < 7; ii++) {
            data.append("'").append(num - 6 + ii).append("周'");
            if (ii != 6) {
                data.append(",");
            }
        }
        data.append("];");
        data.append("const right2_data2= [");
        for (int i = 6; i >= 0; i--) {
            data.append(listsize[i]);
            if (i != 0) {
                data.append(",");
            }
        }
        data.append("];");
        return data.toString();
    }

    private static String right3(int num) {
        StringBuilder data = new StringBuilder();
        data.append("const right3= [");
        int len = list_oid.size();
        for (int ii = 0; ii < len; ii++) {
            data.append("[").append(ii + 1).append(",'");
            for (int i1 = 0; i1 < list.size(); i1++) {
                if (list.get(i1).getNiu_id() == list_oid.get(ii).getNiu_id()) {
                    if (i1 == ii) {
                        data.append("⊜");
                    } else if (i1 < ii) {
                        data.append("⇪");
                    } else {
                        data.append("⇩");
                    }
                    break;
                }
                if (i1 == list.size() - 1) {
                    data.append("⌀");
                }
            }
            data.append("','").append(list_oid.get(ii).getClassInfo()).append("','");
            data.append(list_oid.get(ii).getName()).append("','");
            data.append(list_oid.get(ii).getNiu_total_score()).append("','");
            data.append(list_oid.get(ii).getNiu_time()).append("']");
            if (ii != len - 1) {
                data.append(",");
            }
        }
        System.out.println();
        data.append("];");

        return data.toString();
    }

    private static List<NiuStudent> setListNiuStudent(int num, List<NiuStudent> list2) {
        List<Integer> niuIds = studentMapper.getNiuIds();
        for (Integer niuId : niuIds) {
            NiuStudent niuStudent = studentMapper.getStudentByIdAndTableName("user_table_" + num, niuId);
            // 处理查询到的学生和相关 User_niu 信息
            if (niuStudent != null) {
                list2.add(niuStudent);
            }
        }
        // 创建一个Comparator接口实现，用于比较两个NiuStudent对象的niu_total_score属性
        Comparator<NiuStudent> comparator = new Comparator<NiuStudent>() {
            @Override
            public int compare(NiuStudent s1, NiuStudent s2) {
                if (s1.getNiu_total_score() == null) {
                    return 1;
                }
                if (s2.getNiu_total_score() == null) {
                    return -1;
                }
                // 将字符串转换为double类型后进行比较
                double score1 = Double.parseDouble(s1.getNiu_total_score());
                double score2 = Double.parseDouble(s2.getNiu_total_score());
                if (score2 > score1) {
                    return 1;
                } else if (score2 < score1) {
                    return -1;
                } else {
                    return s1.getNiu_time().compareTo(s2.getNiu_time());
                }
            }
        };
        // 使用Collections.sort方法对列表进行排序
        Collections.sort(list2, comparator);
        return list2;
    }
}
